<?php
/**
 * Introduction: 前台分类目录
 * @author: 杨陈鹏
 * @date: 2016/4/7 23:00
 * @email: yangchenpeng@cdlinglu.com
 */

namespace WeChat\Controller\Category;


use Think\Controller;

class IndexController extends Controller
{
    /**
     * Introduction: 获取分类列表
     * @author: 杨陈鹏
     * @date: 2016/4/7 23:00
     * @email: yangchenpeng@cdlinglu.com
     */
    public function lists()
    {

        $logic = D('Common/Category', 'Logic');


        $data = $logic::getData(['pid' => 0], '0,100000', 'id,name,thumb');

        $data = $data['data'];

        foreach ($data as $k => $v) {

            $second = $logic::getData(['pid' => $v['id']], '0,100000', 'id,name');

            $second = $second['data'];

            if ($second) {

                foreach ($second as $key => $val) {

                    $second[$key]['child'] = $logic::getChilds($val['id'], 'id,name');

                }

                $data[$k]['child'] = $second;

            }

        }

        outPut(['code' => 200, 'data' => $data]);

    }
}